import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
import { getToken, setToken, removeToken } from '@/utils/auth'

export default new Vuex.Store({
  state: {
    username:window.localStorage.getItem('user'||'[]'==null?'':JSON.parse(window.localStorage.getItem('username'||''))),
    token: getToken(),
    name: '',
    avatar: '',
    roles: [],
    permissions: []
  },
  mutations: {
    SET_TOKEN: (state, token) => {
      state.token = token
    },
    SET_NAME: (state, name) => {
      state.name = name
    },
    SET_AVATAR: (state, avatar) => {
      state.avatar = avatar
    },
    SET_ROLES: (state, roles) => {
      state.roles = roles
    },
    SET_PERMISSIONS: (state, permissions) => {
      state.permissions = permissions
    },
    login(state,username){
      state.username=username
      window.localStorage.setItem("username",JSON.stringify(username))
    }
  },
  actions: {
  },
  modules: {
  }
})
